import Home from '@/components/primer/Home.vue';
import Introduction from '@/components/primer/Introduction.vue';
import Basic from '@/components/primer/Basic.vue';
import Advanced from '@/components/primer/Advanced.vue';

import Person from '@/components/params/Person.vue';
import Human from '@/components/params/Human.vue';

import Topic from '@/components/wendao/TopicView.vue';
import Explains from '@/components/wendao/ExplainsView.vue';

const routes = [
    { 
        name: 'rootRoute',
        path: '/', 
        redirect: '/home'
    },
    // 每个路由都需要映射到一个组件，使用 component 指定组件
    { 
        name: 'homeRoute',
        path: '/home', 
        component: Home,
        alias: ['/index', '/home/page']
    } ,
    // 路由对象 也称作 路由记录
    { path: '/introduction', component: Introduction } ,
    { path: '/basic', component: Basic } ,
    { path: '/advanced' , component: Advanced },
    {
        name: 'personRoute',
        path: '/person',
        component: Person,
        alias: '/nashui'
    },
    {
        name: 'humanRoute',
        path: '/human/:id/:name',
        component: Human
    },
    {
        name: 'goodsRoute',
        path: '/goods',
        component: () => import('@/components/cart/Goods.vue')
    },
    {
        name: 'cartRoute',
        path: '/cart',
        component: () => import('@/components/cart/Cart.vue')
    },
    {
        name: 'userOperation',
        path: '/user',
        components: {
          default: () => import('@/components/user/UserView.vue'),
          sidebar: () => import('@/components/user/NavigatorBar.vue')
        }
    },
    {
        path: '/topic/:id',
        /*首先明确父路由对应的路由组件都有谁*/
        components: {
          default: Topic,
          sidebar: () => import('@/components/wendao/NavigatorBar.vue')
        },
        /*定义子路由(即嵌套路由)*/
        children: [
          {
            path: '',
            component: Explains
          },
          { 
            name: 'explains', 
            /* /topic/1/explains */
            path: 'explains',
            component: Explains
          }
        ]
    }
];

export default routes;